<?php

namespace Admin\Controller;

class RecruitmentController extends LoginController {
	public function __construct() {
		parent::__construct ();
		$this->db = D ( "Recruitment" );
		layout ( false );
	}
	public function index() {
		if (IS_POST) {
			$arr = $_POST;
			$id = $arr ['id'];
			$arr ['up_date'] = date ( "Y-m-d H:i:s" );
			
			if (empty ( $id )) { // 新增
				$arr ['creat_date'] = $arr ['up_date'];
				$arr ["user"] = $this->user_id;
				if ($this->checkToken( $arr )){
					$this->db->add ( $arr );
				}
				
			} else { // 修改
				if ($this->checkToken ( $arr )){
					$this->db->save ( $arr );
				}
			}
		 	$this->success("保存成功！",$_SERVER['HTTP_REFERER'],5);
		 	exit();
		}
		$count = $this->db->count ();
		$Page = page ( $count, 10 );
		$show = $Page->show ();
		$orderby ['id'] = 'desc';
		$list = $this->db->order ( $orderby )->limit ( $Page->firstRow . ',' . $Page->listRows )->select ();
		
		$this->assign ( array (
				'list' => $list,
				'show' => $show 
		) );
		$this->display ();
	}
	
	// 删除职位
	public function recruitmentDe() {
		if (IS_POST) {
			$id = $_POST ['id'];
			echo $this->db->where ( "id=$id" )->delete ();
		}
	}
	public function add() {
		if (IS_GET && ! empty ( $_GET ['id'] )) {
			$data = $this->db->find ( $_GET ['id'] );
			$this->assign ( array (
					'data' => $data 
			) );
		}
		$this->display ();
	}
	
	/**
	 * 链接排序
	 *
	 * @access public
	 * @param int $id
	 *        	链接id
	 */
	public function listorder() {
		if (IS_POST) {
			$arr = I("post.");
			$arr = $arr ['listorder'];
			foreach ( $arr as $key => $r ) {
				$this->db->where ( "id=$key" )->save ( array (
						'listorder' => $r
				) );
			}
			$this->index();
		}
	}
	
}
?>